package oneroom.admin.oneroom;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import oneroom.comm.ThumbnailUtil;
import oneroom.comm.commPath;

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.ByTimestampFileRenamePolicy;

public class roomService {

	/**
	 * 분기
	 * @param requests
	 * @return
	 */
	public roomModel setRequest(HttpServletRequest requests){
		boolean returnVal = true;
		MultipartRequest request = null;
		roomModel returnValue	=	new roomModel();
		roomDao 	dao 		= 	new roomDao();
		String gubun = requests.getParameter("gubun") == null ? "" :requests.getParameter("gubun") ;
		if(gubun != null && gubun.equals("")){ //등록 및 수정
			try {
				request = new MultipartRequest(requests, commPath.UPLOAD_PATH,
						commPath.SIZELIMIT, "UTF-8", new ByTimestampFileRenamePolicy("room"));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			gubun = request.getParameter("gubun") == null ? "" :request.getParameter("gubun");
			if(gubun != null && (gubun.equals("I") || gubun.equals("CI"))){
				 returnValue 	= setParame(request);
				 returnValue.setCreateid((String)requests.getSession().getAttribute("id"));
				 returnValue.setGubun(gubun);
				 returnValue.setReturnVal(dao.getInsert(returnValue));
				 if(gubun.equals("CI")){
					 returnValue.setOneroom_seq(dao.getMaxCnt(returnValue.getCreateid()));
				 }
				 
			}else if(gubun != null && gubun.equals("U")){
				returnValue 	= setParame(request);
				returnValue.setCreateid((String)requests.getSession().getAttribute("id"));
				returnValue.setGubun(gubun);
				returnValue.setReturnVal(dao.getUpdate(returnValue));
			}
		}else if(gubun.equals("D")){ //삭제
			String oneroom_seq = requests.getParameter("oneroom_seq") == null ? "0" : requests.getParameter("oneroom_seq");
			returnValue.setOneroom_seq(Integer.parseInt(oneroom_seq));
			fileDelete(requests.getParameter("photo1_path") 	== null ? "" : requests.getParameter("photo1_path"));
			fileDelete(requests.getParameter("photo1_small") 	== null ? "" : requests.getParameter("photo1_small"));
			fileDelete(requests.getParameter("photo1_big") 		== null ? "" : requests.getParameter("photo1_big"));
			fileDelete(requests.getParameter("photo2_path") 	== null ? "" : requests.getParameter("photo2_path"));
			fileDelete(requests.getParameter("photo2_small") 	== null ? "" : requests.getParameter("photo2_small"));
			fileDelete(requests.getParameter("photo2_big") 		== null ? "" : requests.getParameter("photo2_big"));
			fileDelete(requests.getParameter("photo3_path") 	== null ? "" : requests.getParameter("photo3_path"));
			fileDelete(requests.getParameter("photo3_small") 	== null ? "" : requests.getParameter("photo3_small"));
			fileDelete(requests.getParameter("photo3_big") 		== null ? "" : requests.getParameter("photo3_big"));
			fileDelete(requests.getParameter("photo4_path") 	== null ? "" : requests.getParameter("photo4_path"));
			fileDelete(requests.getParameter("photo4_small") 	== null ? "" : requests.getParameter("photo4_small"));
			fileDelete(requests.getParameter("photo4_big") 		== null ? "" : requests.getParameter("photo4_big"));
			fileDelete(requests.getParameter("photo5_path") 	== null ? "" : requests.getParameter("photo5_path"));
			fileDelete(requests.getParameter("photo5_small") 	== null ? "" : requests.getParameter("photo5_small"));
			fileDelete(requests.getParameter("photo5_big") 		== null ? "" : requests.getParameter("photo5_big"));
			fileDelete(requests.getParameter("photo6_path") 	== null ? "" : requests.getParameter("photo6_path"));
			fileDelete(requests.getParameter("photo7_small") 	== null ? "" : requests.getParameter("photo6_small"));
			fileDelete(requests.getParameter("photo6_big") 		== null ? "" : requests.getParameter("photo6_big"));
			returnValue.setGubun(gubun);
			returnValue.setReturnVal(dao.getDelete(oneroom_seq));
		}else if(gubun.equals("MD")){ //삭제
			String oneroom_seq = requests.getParameter("oneroom_seq") == null ? "" : requests.getParameter("oneroom_seq");
			String seq[] = oneroom_seq.split(",");
			returnValue.setGubun(gubun);
			boolean returnDateVal= false;
			for(int i=0; i<seq.length;i++){
				returnDateVal = dao.getDelete(seq[i]);
			}
			returnValue.setReturnVal(returnDateVal);
			returnValue.setGubun(gubun);

		}else{
			String oneroom_seq = requests.getParameter("oneroom_seq") == null ? "" : requests.getParameter("oneroom_seq");
			String seq[] = oneroom_seq.split(",");
			returnValue.setGubun(gubun);
			boolean returnDateVal= false;
			for(int i=0; i<seq.length;i++){
				if(gubun.equals("R")){
					returnDateVal = dao.getResetupdate(seq[i]);
				}else if(gubun.equals("A")){
					returnDateVal = dao.getDateupdate(seq[i]);
				}
			}
			if(gubun.equals("A")){
				dao.getHitHistory((String)requests.getSession().getAttribute("id"));
			}			
			returnValue.setReturnVal(returnDateVal);
			returnValue.setGubun(gubun);
		}
		return returnValue;
	}
	
	/**
	 * 파라미터 셋팅
	 * @param request
	 * @return
	 */
	private roomModel setParame(MultipartRequest request){
		roomModel returnValue 	= 	new roomModel();
		  returnValue.setOneroom_seq(Integer.parseInt((request.getParameter("oneroom_seq") == null ? "0" : request.getParameter("oneroom_seq"))));
		  returnValue.setAddress1(request.getParameter("address1" ) 	== null ? "" :request.getParameter("address1"));
		  returnValue.setAddress2(request.getParameter("address2" ) 	== null ? "" :request.getParameter("address2"));
		  returnValue.setAddress3(request.getParameter("address3" ) 	== null ? "" :request.getParameter("address3"));
		  returnValue.setAddress4(request.getParameter("address4" ) 	== null ? "" :request.getParameter("address4"));
		  returnValue.setAddress5(request.getParameter("address5" ) 	== null ? "" :request.getParameter("address5"));
		  returnValue.setZipcode1(request.getParameter("zipcode1" ) 	== null ? "" :request.getParameter("zipcode1"));
		  returnValue.setZipcode2(request.getParameter("zipcode2" ) 	== null ? "" :request.getParameter("zipcode2"));
		  returnValue.setRoomnumber(request.getParameter("roomnumber" ) == null ? "" :request.getParameter("roomnumber"));
		  returnValue.setRoomkind(request.getParameter("roomkind" ) 	== null ? "" :request.getParameter("roomkind"));
		  returnValue.setRoomarea(request.getParameter("roomarea" ) 	== null ? "" :request.getParameter("roomarea"));
		  returnValue.setRoommoney(request.getParameter("roommoney" )	== null ? "" :request.getParameter("roommoney"));
		  returnValue.setCharter(request.getParameter("charter" )	== null ? "" :request.getParameter("charter"));
		  returnValue.setRoomfloor1(request.getParameter("roomfloor1" ) == null ? "" :request.getParameter("roomfloor1"));
		  returnValue.setRoomfloor2(request.getParameter("roomfloor2" ) == null ? "" :request.getParameter("roomfloor2"));
		  returnValue.setRoommonth1(request.getParameter("roommonth1" ) == null ? "" :request.getParameter("roommonth1"));
		  returnValue.setRoommonth2(request.getParameter("roommonth2" ) == null ? "" :request.getParameter("roommonth2"));
		  returnValue.setCar(request.getParameter("car" ) 				== null ? "" :request.getParameter("car"));
		  returnValue.setManagemoney(request.getParameter("managemoney" ) == null ? "" :request.getParameter("managemoney"));
		  returnValue.setSubway1(request.getParameter("subway1" ) 		== null ? "" :request.getParameter("subway1"));
		  returnValue.setSubway2(request.getParameter("subway2" ) 		== null ? "" :request.getParameter("subway2"));
		  returnValue.setSubway3(request.getParameter("subway3" ) 		== null ? "" :request.getParameter("subway3"));
		  returnValue.setHeating(request.getParameter("heating" ) 		== null ? "" :request.getParameter("heating"));
		  returnValue.setAirconditioning(request.getParameter("airconditioning" ) == null ? "" :request.getParameter("airconditioning"));
		  returnValue.setUniversity1(request.getParameter("university1" ) 	== null ? "" :request.getParameter("university1"));
		  returnValue.setUniversity2(request.getParameter("university2" ) 	== null ? "" :request.getParameter("university2"));
		  returnValue.setUniversity3(request.getParameter("university3" ) 	== null ? "" :request.getParameter("university3"));
		  returnValue.setLease(request.getParameter("lease" ) 				== null ? "" :request.getParameter("lease"));
		  returnValue.setLeaseyear(request.getParameter("leaseyear" ) 	== null ? "" :request.getParameter("leaseyear"));
		  returnValue.setLeasemonth(request.getParameter("leasemonth" ) == null ? "" :request.getParameter("leasemonth"));
		  returnValue.setLeaseday(request.getParameter("leaseday" ) 	== null ? "" :request.getParameter("leaseday"));
		  returnValue.setRoomoption(request.getParameter("roomoption" ) 	== null ? "" :request.getParameter("roomoption"));
		  returnValue.setContinuously(request.getParameter("continuously" ) 	== null ? "" :request.getParameter("continuously"));		  
		  
		  String [] furniture1  = request.getParameterValues("furniture1");
		  if(furniture1 != null){
			  String value = "";
			  for(int i = 0; i<furniture1.length; i++){
				  if(i != furniture1.length){
					  value = value + furniture1[i]+",";
				  }else{
					  value = value + furniture1[i];
				  }
			  }
			  returnValue.setFurniture1(value); 
		  }else{
			  returnValue.setFurniture1(""); 
		  }
		  //returnValue.setFurniture1(request.getParameter("furniture1" ) == null ? "" :request.getParameter("furniture1"));
		  returnValue.setFurniture2(request.getParameter("furniture2" ) == null ? "" :request.getParameter("furniture2"));
		  returnValue.setFurniture3(request.getParameter("furniture3" ) == null ? "" :request.getParameter("furniture3"));
		  returnValue.setFurniture4(request.getParameter("furniture4" ) == null ? "" :request.getParameter("furniture4"));
		  String [] appliances1  = request.getParameterValues("appliances1");
		  if(appliances1 != null){
			  String value = "";
			  for(int i = 0; i<appliances1.length; i++){
				  if(i != appliances1.length){
					  value = value + appliances1[i]+",";
				  }else{
					  value = value + appliances1[i];
				  }
			  }
			  returnValue.setAppliances1(value); 
		  }else{
			  returnValue.setAppliances1(""); 
		  }
		  //returnValue.setAppliances1(request.getParameter("appliances1" ) == null ? "" :request.getParameter("appliances1"));
		  returnValue.setAppliances2(request.getParameter("appliances2" ) == null ? "" :request.getParameter("appliances2"));
		  returnValue.setAppliances3(request.getParameter("appliances3" ) == null ? "" :request.getParameter("appliances3"));
		  returnValue.setAppliances4(request.getParameter("appliances4" ) == null ? "" :request.getParameter("appliances4"));
		  returnValue.setAppliances5(request.getParameter("appliances5" ) == null ? "" :request.getParameter("appliances5"));
		  returnValue.setAppliances6(request.getParameter("appliances6" ) == null ? "" :request.getParameter("appliances6"));
		  returnValue.setAppliances7(request.getParameter("appliances7" ) == null ? "" :request.getParameter("appliances7"));
		  String [] kitchen1  = request.getParameterValues("kitchen1");
		  if(kitchen1 != null){
			  String value = "";
			  for(int i = 0; i<kitchen1.length; i++){
				  if(i != kitchen1.length){
					  value = value + kitchen1[i]+",";
				  }else{
					  value = value + kitchen1[i];
				  }
			  }
			  returnValue.setKitchen1(value); 
		  }else{
			  returnValue.setKitchen1(""); 
		  }
		  //returnValue.setKitchen1(request.getParameter("kitchen1" ) == null ? "" :request.getParameter("kitchen1"));
		  returnValue.setKitchen2(request.getParameter("kitchen2" ) == null ? "" :request.getParameter("kitchen2"));
		  returnValue.setKitchen3(request.getParameter("kitchen3" ) == null ? "" :request.getParameter("kitchen3"));
		  returnValue.setKitchen4(request.getParameter("kitchen4" ) == null ? "" :request.getParameter("kitchen4"));
		  returnValue.setKitchen5(request.getParameter("kitchen5" ) == null ? "" :request.getParameter("kitchen5"));
		  String [] security1  = request.getParameterValues("security1");
		  if(security1 != null){
			  String value = "";
			  for(int i = 0; i<security1.length; i++){
				  if(i != security1.length){
					  value = value + security1[i]+",";
				  }else{
					  value = value + security1[i];
				  }
			  }
			  returnValue.setSecurity1(value); 
		  }else{
			  returnValue.setSecurity1(""); 
		  }
		  //returnValue.setSecurity1(request.getParameter("security1" ) == null ? "" :request.getParameter("security1"));
		  returnValue.setSecurity2(request.getParameter("security2" ) == null ? "" :request.getParameter("security2"));
		  returnValue.setSecurity3(request.getParameter("security3" ) == null ? "" :request.getParameter("security3"));
		  returnValue.setSecurity4(request.getParameter("security4" ) == null ? "" :request.getParameter("security4"));
		  returnValue.setSecurity5(request.getParameter("security5" ) == null ? "" :request.getParameter("security5"));
		  returnValue.setSecurity6(request.getParameter("security6" ) == null ? "" :request.getParameter("security6"));
		  String [] facility1  = request.getParameterValues("facility1");
		  if(facility1 != null){
			  String value = "";
			  for(int i = 0; i<facility1.length; i++){
				  if(i != facility1.length){
					  value = value + facility1[i]+",";
				  }else{
					  value = value + facility1[i];
				  }
			  }
			  returnValue.setFacility1(value); 
		  }else{
			  returnValue.setFacility1(""); 
		  }
		  //returnValue.setFacility1(request.getParameter("facility1" ) == null ? "" :request.getParameter("facility1"));
		  returnValue.setFacility2(request.getParameter("facility2" ) == null ? "" :request.getParameter("facility2"));
		  returnValue.setFacility3(request.getParameter("facility3" ) == null ? "" :request.getParameter("facility3"));
		  returnValue.setFacility4(request.getParameter("facility4" ) == null ? "" :request.getParameter("facility4"));
		  returnValue.setFacility5(request.getParameter("facility5" ) == null ? "" :request.getParameter("facility5"));
		  returnValue.setTitle(request.getParameter("title" ) 		== null ? "" :request.getParameter("title"));
		  returnValue.setContent(request.getParameter("content" ) 	== null ? "" :request.getParameter("content"));
		  returnValue.setPerson(request.getParameter("person" ) 	== null ? "" :request.getParameter("person"));
		  returnValue.setTel1(request.getParameter("tel1" ) 		== null ? "" :request.getParameter("tel1"));
		  returnValue.setTel2(request.getParameter("tel2" ) 		== null ? "" :request.getParameter("tel2"));
		  returnValue.setTel3(request.getParameter("tel3" ) 		== null ? "" :request.getParameter("tel3"));
		  returnValue.setPhoto1(request.getFilesystemName("photo1") == null ? "" :request.getFilesystemName("photo1"));
		  returnValue.setPhoto2(request.getFilesystemName("photo2") == null ? "" :request.getFilesystemName("photo2"));
		  returnValue.setPhoto3(request.getFilesystemName("photo3") == null ? "" :request.getFilesystemName("photo3"));
		  returnValue.setPhoto4(request.getFilesystemName("photo4") == null ? "" :request.getFilesystemName("photo4"));
		  returnValue.setPhoto5(request.getFilesystemName("photo5") == null ? "" :request.getFilesystemName("photo5"));
		  returnValue.setPhoto6(request.getFilesystemName("photo6") == null ? "" :request.getFilesystemName("photo6"));
		  if(request.getParameter("gubun").equals("I") || request.getParameter("gubun").equals("CI")){
			  if(returnValue.getContinuously() != null &&  returnValue.getContinuously().equals("Y")){
					returnValue.setPhoto1(request.getParameter("photo1") == null ? "" :request.getParameter("photo1"));
					returnValue.setPhoto2(request.getParameter("photo2") == null ? "" :request.getParameter("photo2"));
					returnValue.setPhoto3(request.getParameter("photo3") == null ? "" :request.getParameter("photo3"));
					returnValue.setPhoto4(request.getParameter("photo4") == null ? "" :request.getParameter("photo4"));
					returnValue.setPhoto5(request.getParameter("photo5") == null ? "" :request.getParameter("photo5"));
					returnValue.setPhoto6(request.getParameter("photo6") == null ? "" :request.getParameter("photo6"));				  
					returnValue.setPhoto1_small(request.getParameter("photo1_small") == null ? "" :request.getParameter("photo1_small"));
					returnValue.setPhoto1_big(request.getParameter("photo1_big") == null ? "" :request.getParameter("photo1_big"));
					returnValue.setPhoto2_small(request.getParameter("photo2_small") == null ? "" :request.getParameter("photo2_small"));
					returnValue.setPhoto2_big(request.getParameter("photo2_big") == null ? "" :request.getParameter("photo2_big"));
					returnValue.setPhoto3_small(request.getParameter("photo3_small") == null ? "" :request.getParameter("photo3_small"));
					returnValue.setPhoto3_big(request.getParameter("photo3_big") == null ? "" :request.getParameter("photo3_big"));
					returnValue.setPhoto4_small(request.getParameter("photo4_small") == null ? "" :request.getParameter("photo4_small"));
					returnValue.setPhoto4_big(request.getParameter("photo4_big") == null ? "" :request.getParameter("photo4_big"));
					returnValue.setPhoto5_small(request.getParameter("photo5_small") == null ? "" :request.getParameter("photo5_small"));
					returnValue.setPhoto5_big(request.getParameter("photo5_big") == null ? "" :request.getParameter("photo5_big"));
					returnValue.setPhoto6_small(request.getParameter("photo6_small") == null ? "" :request.getParameter("photo6_small"));
					returnValue.setPhoto6_big(request.getParameter("photo6_big") == null ? "" :request.getParameter("photo6_big"));
			  }else{
				  if(returnValue.getPhoto1() != null && !returnValue.getPhoto1().equals("")){
					  	createThumbnailFiles(returnValue.getPhoto1());
						String photoName  = returnValue.getPhoto1().substring(0, returnValue.getPhoto1().indexOf("."));
						String photoExtension  = returnValue.getPhoto1().substring(returnValue.getPhoto1().indexOf("."),returnValue.getPhoto1().length() );
						
						returnValue.setPhoto1_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto1_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  	returnValue.setPhoto1_small("");
						returnValue.setPhoto1_big("");
				  }
				  if(returnValue.getPhoto2() != null && !returnValue.getPhoto2().equals("")){
					  	createThumbnailFiles(returnValue.getPhoto2());
						String photoName  = returnValue.getPhoto2().substring(0, returnValue.getPhoto2().indexOf("."));
						String photoExtension  = returnValue.getPhoto2().substring(returnValue.getPhoto2().indexOf("."),returnValue.getPhoto2().length() );
						
						returnValue.setPhoto2_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto2_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  	returnValue.setPhoto2_small("");
						returnValue.setPhoto2_big("");			  
				  }
				  if(returnValue.getPhoto3() != null && !returnValue.getPhoto3().equals("")){
					  	createThumbnailFiles(returnValue.getPhoto3());
						String photoName  = returnValue.getPhoto3().substring(0, returnValue.getPhoto3().indexOf("."));
						String photoExtension  = returnValue.getPhoto3().substring(returnValue.getPhoto3().indexOf("."),returnValue.getPhoto3().length() );
						
						returnValue.setPhoto3_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto3_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  	returnValue.setPhoto3_small("");
						returnValue.setPhoto3_big("");			  
				  }
				  if(returnValue.getPhoto4() != null && !returnValue.getPhoto4().equals("")){
					  	createThumbnailFiles(returnValue.getPhoto4());
						String photoName  = returnValue.getPhoto4().substring(0, returnValue.getPhoto4().indexOf("."));
						String photoExtension  = returnValue.getPhoto4().substring(returnValue.getPhoto4().indexOf("."),returnValue.getPhoto4().length() );
						
						returnValue.setPhoto4_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto4_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  	returnValue.setPhoto4_small("");
						returnValue.setPhoto4_big("");			  
				  }
				  if(returnValue.getPhoto5() != null && !returnValue.getPhoto5().equals("")){
					  	createThumbnailFiles(returnValue.getPhoto5());
						String photoName  = returnValue.getPhoto5().substring(0, returnValue.getPhoto5().indexOf("."));
						String photoExtension  = returnValue.getPhoto5().substring(returnValue.getPhoto5().indexOf("."),returnValue.getPhoto5().length() );
						
						returnValue.setPhoto5_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto5_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  	returnValue.setPhoto5_small("");
						returnValue.setPhoto5_big("");			  
				  }
				  if(returnValue.getPhoto6() != null && !returnValue.getPhoto6().equals("")){
					  	createThumbnailFiles(returnValue.getPhoto6());
						String photoName  = returnValue.getPhoto6().substring(0, returnValue.getPhoto6().indexOf("."));
						String photoExtension  = returnValue.getPhoto6().substring(returnValue.getPhoto6().indexOf("."),returnValue.getPhoto6().length() );
						
						returnValue.setPhoto6_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto6_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  	returnValue.setPhoto6_small("");
						returnValue.setPhoto6_big("");			  
				  }
			  }
		  /*}else if(request.getParameter("gubun").equals("CI")){
			  	returnValue.setPhoto1_small(request.getFilesystemName("photo1_small") == null ? "" :request.getFilesystemName("photo1_small"));
				returnValue.setPhoto1_big(request.getFilesystemName("photo1_big") == null ? "" :request.getFilesystemName("photo1_big"));
				returnValue.setPhoto2_small(request.getFilesystemName("photo2_small") == null ? "" :request.getFilesystemName("photo2_small"));
				returnValue.setPhoto2_big(request.getFilesystemName("photo2_big") == null ? "" :request.getFilesystemName("photo2_big"));
				returnValue.setPhoto3_small(request.getFilesystemName("photo3_small") == null ? "" :request.getFilesystemName("photo3_small"));
				returnValue.setPhoto3_big(request.getFilesystemName("photo3_big") == null ? "" :request.getFilesystemName("photo3_big"));
				returnValue.setPhoto4_small(request.getFilesystemName("photo4_small") == null ? "" :request.getFilesystemName("photo4_small"));
				returnValue.setPhoto4_big(request.getFilesystemName("photo4_big") == null ? "" :request.getFilesystemName("photo4_big"));
				returnValue.setPhoto5_small(request.getFilesystemName("photo5_small") == null ? "" :request.getFilesystemName("photo5_small"));
				returnValue.setPhoto5_big(request.getFilesystemName("photo5_big") == null ? "" :request.getFilesystemName("photo5_big"));
				returnValue.setPhoto6_small(request.getFilesystemName("photo6_small") == null ? "" :request.getFilesystemName("photo6_small"));
				returnValue.setPhoto6_big(request.getFilesystemName("photo6_big") == null ? "" :request.getFilesystemName("photo6_big"));
		*/	  
		  }else if(request.getParameter("gubun").equals("U")){
			  if(request.getParameter("delphoto1") != null && request.getParameter("delphoto1").equals("Y")){//삭제를 선택 하였을 경우
				  returnValue.setPhoto1("");
				  returnValue.setPhoto1_small("");
				  returnValue.setPhoto1_big("");
				  //파일 삭제
				  fileDelete(request.getParameter("photo1_path") == null ? "" : request.getParameter("photo1_path"));
				  fileDelete(request.getParameter("photo1_small") == null ? "" : request.getParameter("photo1_small"));
				  fileDelete(request.getParameter("photo1_big") == null ? "" : request.getParameter("photo1_big"));
			  }else{
				  if(returnValue.getPhoto1() != null && !returnValue.getPhoto1().equals("")){ //새로운 파일을 등록 하였을 경우
					  	//파일 삭제
						fileDelete(request.getParameter("photo1_path") == null ? "" : request.getParameter("photo1_path"));
						fileDelete(request.getParameter("photo1_small") == null ? "" : request.getParameter("photo1_small"));
						fileDelete(request.getParameter("photo1_big") == null ? "" : request.getParameter("photo1_big"));
					  	createThumbnailFiles(returnValue.getPhoto1());
						String photoName  = returnValue.getPhoto1().substring(0, returnValue.getPhoto1().indexOf("."));
						String photoExtension  = returnValue.getPhoto1().substring(returnValue.getPhoto1().indexOf("."),returnValue.getPhoto1().length() );
						
						returnValue.setPhoto1_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto1_big(photoName+"_thumb457"+photoExtension);
				  }else{//액션이 없을 경우
					  	returnValue.setPhoto1(request.getParameter("photo1_path") == null ? "" : request.getParameter("photo1_path"));
					  	returnValue.setPhoto1_small(request.getParameter("photo1_small") == null ? "" : request.getParameter("photo1_small"));
						returnValue.setPhoto1_big(request.getParameter("photo1_big") == null ? "" : request.getParameter("photo1_big"));
				  } 
			  }
			  
			  if(request.getParameter("delphoto2") != null && request.getParameter("delphoto2").equals("Y")){//삭제를 선택 하였을 경우
				  returnValue.setPhoto2("");
				  returnValue.setPhoto2_small("");
				  returnValue.setPhoto2_big("");
				  //파일 삭제
				  fileDelete(request.getParameter("photo2_path") == null ? "" : request.getParameter("photo2_path"));
				  fileDelete(request.getParameter("photo2_small") == null ? "" : request.getParameter("photo2_small"));
				  fileDelete(request.getParameter("photo2_big") == null ? "" : request.getParameter("photo2_big"));
			  }else{
				  if(returnValue.getPhoto2() != null && !returnValue.getPhoto2().equals("")){
					//파일 삭제
						fileDelete(request.getParameter("photo2_path") == null ? "" : request.getParameter("photo2_path"));
						fileDelete(request.getParameter("photo2_small") == null ? "" : request.getParameter("photo2_small"));
						fileDelete(request.getParameter("photo2_big") == null ? "" : request.getParameter("photo2_big"));
						
					  	createThumbnailFiles(returnValue.getPhoto2());
						String photoName  = returnValue.getPhoto2().substring(0, returnValue.getPhoto2().indexOf("."));
						String photoExtension  = returnValue.getPhoto2().substring(returnValue.getPhoto2().indexOf("."),returnValue.getPhoto2().length() );
						
						returnValue.setPhoto2_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto2_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  returnValue.setPhoto2(request.getParameter("photo2_path") == null ? "" : request.getParameter("photo2_path"));
					  	returnValue.setPhoto2_small(request.getParameter("photo2_small") == null ? "" : request.getParameter("photo2_small"));
						returnValue.setPhoto2_big(request.getParameter("photo2_big") == null ? "" : request.getParameter("photo2_big"));		  
				  }
			  }
			  
			  if(request.getParameter("delphoto3") != null && request.getParameter("delphoto3").equals("Y")){//삭제를 선택 하였을 경우
				  returnValue.setPhoto3("");
				  returnValue.setPhoto3_small("");
				  returnValue.setPhoto3_big("");
				//파일 삭제
				  fileDelete(request.getParameter("photo3_path") == null ? "" : request.getParameter("photo3_path"));
				  fileDelete(request.getParameter("photo3_small") == null ? "" : request.getParameter("photo3_small"));
				  fileDelete(request.getParameter("photo3_big") == null ? "" : request.getParameter("photo3_big"));
			  }else{
				  if(returnValue.getPhoto3() != null && !returnValue.getPhoto3().equals("")){
					//파일 삭제
						fileDelete(request.getParameter("photo3_path") == null ? "" : request.getParameter("photo3_path"));
						fileDelete(request.getParameter("photo3_small") == null ? "" : request.getParameter("photo3_small"));
						fileDelete(request.getParameter("photo3_big") == null ? "" : request.getParameter("photo3_big"));
						
					  	createThumbnailFiles(returnValue.getPhoto3());
						String photoName  = returnValue.getPhoto3().substring(0, returnValue.getPhoto3().indexOf("."));
						String photoExtension  = returnValue.getPhoto3().substring(returnValue.getPhoto3().indexOf("."),returnValue.getPhoto3().length() );
						
						returnValue.setPhoto3_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto3_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  returnValue.setPhoto3(request.getParameter("photo3_path") == null ? "" : request.getParameter("photo3_path"));
					  	returnValue.setPhoto3_small(request.getParameter("photo3_small") == null ? "" : request.getParameter("photo3_small"));
						returnValue.setPhoto3_big(request.getParameter("photo3_big") == null ? "" : request.getParameter("photo3_big"));	  
				  }
			  }
			  
			  if(request.getParameter("delphoto4") != null && request.getParameter("delphoto4").equals("Y")){//삭제를 선택 하였을 경우
				  returnValue.setPhoto4("");
				  returnValue.setPhoto4_small("");
				  returnValue.setPhoto4_big("");
				//파일 삭제
				  fileDelete(request.getParameter("photo4_path") == null ? "" : request.getParameter("photo4_path"));
				  fileDelete(request.getParameter("photo4_small") == null ? "" : request.getParameter("photo4_small"));
				  fileDelete(request.getParameter("photo4_big") == null ? "" : request.getParameter("photo4_big"));
			  }else{
				  if(returnValue.getPhoto4() != null && !returnValue.getPhoto4().equals("")){
					//파일 삭제
						fileDelete(request.getParameter("photo4_path") == null ? "" : request.getParameter("photo4_path"));
						fileDelete(request.getParameter("photo4_small") == null ? "" : request.getParameter("photo4_small"));
						fileDelete(request.getParameter("photo4_big") == null ? "" : request.getParameter("photo4_big"));
						
					  	createThumbnailFiles(returnValue.getPhoto4());
						String photoName  = returnValue.getPhoto4().substring(0, returnValue.getPhoto4().indexOf("."));
						String photoExtension  = returnValue.getPhoto4().substring(returnValue.getPhoto4().indexOf("."),returnValue.getPhoto4().length() );
						
						returnValue.setPhoto4_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto4_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  returnValue.setPhoto4(request.getParameter("photo4_path") == null ? "" : request.getParameter("photo4_path"));
					  	returnValue.setPhoto4_small(request.getParameter("photo4_small") == null ? "" : request.getParameter("photo4_small"));
						returnValue.setPhoto4_big(request.getParameter("photo4_big") == null ? "" : request.getParameter("photo4_big"));		  
				  }
			  }
			  
			  if(request.getParameter("delphoto5") != null && request.getParameter("delphoto5").equals("Y")){//삭제를 선택 하였을 경우
				  returnValue.setPhoto5("");
				  returnValue.setPhoto5_small("");
				  returnValue.setPhoto5_big("");
				//파일 삭제
				  fileDelete(request.getParameter("photo5_path") == null ? "" : request.getParameter("photo5_path"));
				  fileDelete(request.getParameter("photo5_small") == null ? "" : request.getParameter("photo5_small"));
				  fileDelete(request.getParameter("photo5_big") == null ? "" : request.getParameter("photo5_big"));
			  }else{
				  if(returnValue.getPhoto5() != null && !returnValue.getPhoto5().equals("")){
					//파일 삭제
						fileDelete(request.getParameter("photo5_path") == null ? "" : request.getParameter("photo5_path"));
						fileDelete(request.getParameter("photo5_small") == null ? "" : request.getParameter("photo5_small"));
						fileDelete(request.getParameter("photo5_big") == null ? "" : request.getParameter("photo5_big"));
						
					  	createThumbnailFiles(returnValue.getPhoto5());
						String photoName  = returnValue.getPhoto5().substring(0, returnValue.getPhoto5().indexOf("."));
						String photoExtension  = returnValue.getPhoto5().substring(returnValue.getPhoto5().indexOf("."),returnValue.getPhoto5().length() );
						
						returnValue.setPhoto5_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto5_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  returnValue.setPhoto5(request.getParameter("photo5_path") == null ? "" : request.getParameter("photo5_path"));
					  	returnValue.setPhoto5_small(request.getParameter("photo5_small") == null ? "" : request.getParameter("photo5_small"));
						returnValue.setPhoto5_big(request.getParameter("photo5_big") == null ? "" : request.getParameter("photo5_big"));		  
				  }
			  }
			  
			  if(request.getParameter("delphoto6") != null && request.getParameter("delphoto6").equals("Y")){//삭제를 선택 하였을 경우
				  returnValue.setPhoto6("");
				  returnValue.setPhoto6_small("");
				  returnValue.setPhoto6_big("");
				//파일 삭제
				  fileDelete(request.getParameter("photo6_path") == null ? "" : request.getParameter("photo6_path"));
				  fileDelete(request.getParameter("photo6_small") == null ? "" : request.getParameter("photo6_small"));
				  fileDelete(request.getParameter("photo6_big") == null ? "" : request.getParameter("photo6_big"));
			  }else{
				  if(returnValue.getPhoto6() != null && !returnValue.getPhoto6().equals("")){
					//파일 삭제
						fileDelete(request.getParameter("photo6_path") == null ? "" : request.getParameter("photo6_path"));
						fileDelete(request.getParameter("photo6_small") == null ? "" : request.getParameter("photo6_small"));
						fileDelete(request.getParameter("photo6_big") == null ? "" : request.getParameter("photo6_big"));
						
					  	createThumbnailFiles(returnValue.getPhoto6());
						String photoName  = returnValue.getPhoto6().substring(0, returnValue.getPhoto6().indexOf("."));
						String photoExtension  = returnValue.getPhoto6().substring(returnValue.getPhoto6().indexOf("."),returnValue.getPhoto6().length() );
						
						returnValue.setPhoto6_small(photoName+"_thumb92"+photoExtension);
						returnValue.setPhoto6_big(photoName+"_thumb457"+photoExtension);
				  }else{
					  returnValue.setPhoto6(request.getParameter("photo16_path") == null ? "" : request.getParameter("photo6_path"));
					  	returnValue.setPhoto6_small(request.getParameter("photo6_small") == null ? "" : request.getParameter("photo6_small"));
						returnValue.setPhoto6_big(request.getParameter("photo6_big") == null ? "" : request.getParameter("photo6_big"));		  
				  }
			  }
		  }
		  returnValue.setPhoto1_main(request.getParameter("photo1_main" ) == null ? "" :request.getParameter("photo1_main"));
		  returnValue.setPhoto2_main(request.getParameter("photo2_main" ) == null ? "" :request.getParameter("photo2_main"));
		  returnValue.setPhoto3_main(request.getParameter("photo3_main" ) == null ? "" :request.getParameter("photo3_main"));
		  returnValue.setPhoto4_main(request.getParameter("photo4_main" ) == null ? "" :request.getParameter("photo4_main"));
		  returnValue.setPhoto5_main(request.getParameter("photo5_main" ) == null ? "" :request.getParameter("photo5_main"));
		  returnValue.setPhoto6_main(request.getParameter("photo6_main" ) == null ? "" :request.getParameter("photo6_main"));
		  return returnValue;	
	}
	/**
	 * 썸네일 이미지 생성
	 * @param attFile
	 */
	private void createThumbnailFiles(String attFile) {
		try {
			ThumbnailUtil.createThumbnail(commPath.UPLOAD_PATH +
									File.separator + attFile, commPath.THUMB_PRODUCT_SMALL_LENGTH_SIZE,commPath.THUMB_PRODUCT_SMALL_WIDTH_SIZE);
			ThumbnailUtil.createThumbnail(commPath.UPLOAD_PATH +
					File.separator + attFile, commPath.THUMB_PRODUCT_BIG_LENGTH_SIZE,commPath.THUMB_PRODUCT_BIG_WIDTH_SIZE);
			
			
		} catch (Exception e) { }
	}
	/**
	 * 파일 삭제
	 * @param fileName
	 * @return
	 */
	public boolean fileDelete (String fileName){
		boolean returnValue = true;
		fileName = commPath.UPLOAD_PATH+fileName;
		File file = new File(fileName);
		if(file.isFile()){
			returnValue = file.delete();
		}
	
		return returnValue;
	}
	
	/**
	 * 신고 분기
	 * @param requests
	 * @return
	 */
	public reportModel setReport(HttpServletRequest request){
		boolean returnVal = true;
		reportModel returnValue	=	new reportModel();
		roomDao 	dao 		= 	new roomDao();		
		String gubun = request.getParameter("gubun") == null ? "" :request.getParameter("gubun") ;
		String oneroom_seq = request.getParameter("oneroom_seq") == null ? "" :request.getParameter("oneroom_seq") ;		
		if(gubun != null){
			 returnValue 	= setReportParame(request);
			 returnValue.setId((String)request.getSession().getAttribute("id"));
			 returnValue.setName((String)request.getSession().getAttribute("name"));
			 returnValue.setOneroom_seq(oneroom_seq);			 
			 returnValue.setGubun(gubun);
			 returnValue.setReturnVal(dao.getReportInsert(returnValue));
		}
		return returnValue;
	}	
	
	/**
	 * 파라미터 셋팅
	 * @param request
	 * @return
	 */
	private reportModel setReportParame(HttpServletRequest request){
		reportModel returnValue 	= 	new reportModel();
		  returnValue.setOneroom_seq(request.getParameter("oneroom_seq") == null ? "0" : request.getParameter("oneroom_seq"));		  
		  returnValue.setGubun(request.getParameter("gubun" ) 	== null ? "" :request.getParameter("gubun"));
		  returnValue.setName(request.getParameter("name" ) 	== null ? "" :request.getParameter("name"));
		  returnValue.setId(request.getParameter("id" )			== null ? "" :request.getParameter("id"));
		return returnValue;			  
	}	
}















